package cn.tedu.spring.config;

import cn.tedu.spring.file.DBUtil;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class TestSpringConfig {
    public static void main(String[] args) {
        ApplicationContext context = new
                AnnotationConfigApplicationContext(SpringConfig.class);
        DBUtil dbUtil = context.getBean(DBUtil.class);
        String sql = "select * from userinfo";
        try {
            Connection connection = dbUtil.getConnection();
            Statement statement = connection.createStatement();
            ResultSet r = statement.executeQuery(sql);
            while(r.next()){
                System.out.print(r.getString("username")+'\t');
                System.out.print(r.getString("password")+'\t');
                System.out.print(r.getString("nickname")+'\t');
                System.out.println(r.getString("age"));
            }
            connection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
